package band.wukong.practice.java.tip;

/**
 * google算法。效率
 */
public class GoogleFn {
    private static int MAX = 13200000;
    private static int MAX2 = MAX / 10;

    private static int count(int n) {
        int count = 0;
        while (n > 0) {
            int mod = n % 10;
            if (mod == 1)
                count++;
            n = n / 10;
        }
        return count;
    }

    private static void method1() {
        long start = System.currentTimeMillis();
        int result = 0;
        for (int i = 1; i < MAX; i++) {
            result += count(i);
            if (result == i) {
                System.out.println("Find " + i + ", "
                        + (System.currentTimeMillis() - start) + "ms");
            }
        }
    }

    private static void method2() {
        long start = System.currentTimeMillis();
        int result = 0;
        for (int i = 0; i < MAX2; i++) {
            int number = i * 10;
            int value = count(number);
            for (int j = 0; j < 10; j++) {
                result += value;
                if (j == 1) {
                    result++;
                }
                int x = number + j;
                if (x != 0 && result == x) {
                    System.out.println("Find " + x + ", "
                            + (System.currentTimeMillis() - start) + "ms");
                }
            }
        }
    }

    public static void main(String[] args) {
//		method1();
//		method2();

        System.out.println(2 % 10);
        System.out.println(5 % 10);
        System.out.println(6 % 10);
        System.out.println(2 / 10);
        System.out.println(5 / 10);
        System.out.println(6 / 10);

    }
}
